#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
void LongestConsecutiveSequence(vector<int> a)
{
    unordered_map<int,bool> h;
    int n = a.size();
    for(vector<int>::const_iterator iter=a.begin(); iter!=a.end(); iter++)
    {
        if(h.count(*iter)==0)
            h.insert(pair<int,bool>(*iter,false));
    }
    int count,left_key,right_key,max=0,lb=0,ub=0;
    for(vector<int>::const_iterator iter=a.begin(); iter!=a.end(); iter++)
    {
        if(!h.find(*iter)->second)
        {
            count = 1;
            left_key = *iter -1;
            unordered_map<int,bool>::iterator temp = h.find(left_key);
            while(temp!=h.end())
            {
                temp->second = true;
                count++;
                temp = h.find(--left_key);
            }
            right_key = *iter + 1;
            temp = h.find(right_key);
            while(temp!=h.end())
            {
                temp->second = true;
                count++;
                temp = h.find(++right_key);
            }
            if(max<count)
            {
                max = count;
                lb = left_key + 1;
                ub = right_key - 1;
            }
        }
    }
    cout<<"Size:"<<max<<endl;
    for(int i=lb; i<=ub; i++)
    {
        cout<<i<<" ";
    }
}
int main ()
{
    int a[] = {101,2,3,104,5,103,9,102};
    int n = sizeof(a)/sizeof(a[0]);
    vector<int> v(a,a+n);
    LongestConsecutiveSequence(v);
    return 0;
}
